#include "httptest.h"

HttpTest::HttpTest(QObject *parent) : QObject(parent)
{

}

void HttpTest::test(){
    QNetworkAccessManager *manager = new QNetworkAccessManager();

    QObject::connect(manager, &QNetworkAccessManager::finished, [](QNetworkReply *reply) {
        if (reply->error() == QNetworkReply::NoError) {
            // 请求成功，处理返回的数据
            QByteArray response_data = reply->readAll();
            qDebug() << "Response:" << response_data;
        } else {
            // 请求失败，输出错误信息
            qDebug() << "ERROR:" << reply->errorString();
        }
        reply->deleteLater();  // 清理资源
    });

    // 创建请求并设置URL
    QNetworkRequest request(QUrl("http://127.0.0.1:8080/api/getData"));
    request.setHeader(QNetworkRequest::ContentTypeHeader, QVariant("text/plain"));

    // 发送GET请求
    manager->get(request);
}
